//
//  AECommunityPublishNavView.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/19.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AECommunityPublishNavView.h"
#import "AE_Solar-Swift.h"

@interface AECommunityPublishNavView ()

@property (nonatomic, strong) UIView *bgView;

/// 取消
@property (nonatomic, strong) UIButton *btnCancel;

/// 发布
@property (nonatomic, strong) UIButton *btnPublish;

@end

@implementation AECommunityPublishNavView

- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = [UIColor colorWithHexString:@"#FAFAFA"];
    
    [self initWithBgView];
    
    [self initWithBtnCancel];
    
    [self initWithBtnPublish];
}

- (void)initWithBgView {
    if (!_bgView) {
        CGRect frame = CGRectMake(0, self.height - NAVBAR_HEIGHT_NOTOPSPACE, self.width, NAVBAR_HEIGHT_NOTOPSPACE);
        _bgView = [[UIView alloc] initWithFrame:frame];
        [self addSubview:_bgView];
//        _bgView.backgroundColor = [UIColor redColor];
    }
}

- (void)initWithBtnCancel {
    if (!_btnCancel) {
        NSString *title = [AEStringExten localizedValueWithKey:@"取消"];
        UIFont *font = [UIFont systemFontOfSize:19 weight:UIFontWeightMedium];
        float width = [title widthForFont:font] + 2;
        CGRect frame = CGRectMake(15, (self.bgView.height - 30) * 0.5, width, 30);
        _btnCancel = [UIButton createWithButton:self.bgView frame:frame font:font target:self action:@selector(actionWithCancel:) propertiesBlock:^(UIButton * _Nonnull button) {
            [button setTitle:title forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        }];
    }
}

- (void)initWithBtnPublish {
    if (!_btnPublish) {
        NSString *title = [AEStringExten localizedValueWithKey:@"发布"];
        UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
        float width = [title widthForFont:font] + 2 + 17 * 2;
        CGRect frame = CGRectMake(self.bgView.width - 15 - width, (self.bgView.height - 30) * 0.5, width, 30);
        _btnPublish = [UIButton createWithButton:self.bgView frame:frame font:font target:self action:@selector(actionWithPublish:) propertiesBlock:^(UIButton * _Nonnull button) {
            [button setTitle:title forState:UIControlStateNormal];
            [button setTitleColor:kWhiteColor forState:UIControlStateNormal];
            button.backgroundColor = kThemeColor;
            button.layer.cornerRadius = frame.size.height * 0.5;
            button.layer.masksToBounds = YES;
        }];
    }
}

/// 取消
/// - Parameter sender: sender description
- (void)actionWithCancel:(id)sender {
    if (self.touchCancelBlock) {
        self.touchCancelBlock();
    }
}

/// 发布
/// - Parameter sender: sender description
- (void)actionWithPublish:(id)sender {
    if (self.touchPublishBlock) {
        self.touchPublishBlock();
    }
}

@end
